package com.servlet;

import com.dao.imp.FindGoodsDaoImp;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/25 15:33
 **/

@WebServlet(name = "GetGoodByIdServlet", value = "/GetGoodByIdServlet")
public class GetGoodByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(request.getParameter("id"));

        FindGoodsDaoImp findGoodsDaoImp = new FindGoodsDaoImp();
        List goods = findGoodsDaoImp.findGoodById(id);
        JSONObject json = JSONObject.fromObject(goods.get(0));
        response.getWriter().print(json);
    }
}
